package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.SupervisionRecordsDao;
import com.jiantong.work.impl.manager.SupervisionRecordsManager;
import com.jiantong.work.model.SupervisionRecords;
import com.jiantong.work.service.SupervisionRecordsWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;

/**
 * 督查管理-督查记录
 * Created by mz03 on 2017/3/24.
 * @author :zyp
 */
@Slf4j
@Service
@RpcProvider
public class SupervisionRecordsWriteServiceImpl implements SupervisionRecordsWriteService{

    private final SupervisionRecordsManager supervisionRecordsManager;

    @Autowired
    public SupervisionRecordsWriteServiceImpl(SupervisionRecordsManager supervisionRecordsManager){
        this.supervisionRecordsManager = supervisionRecordsManager;
    }
    /**
     * 添加
     *
     * @param supervisionRecords 单据对象
     * @param toStatus 状态
     * @return 主键 id
     */
    @Override
    public Response<Map<String,Object>> create(SupervisionRecords supervisionRecords, Integer toStatus) {
        try{
           Map<String,Object> map = supervisionRecordsManager.createSupervisionRecords(supervisionRecords,toStatus);
            return Response.ok(map);
        }catch(Exception e){
            log.error("failed.create {},case:{}",supervisionRecords, Throwables.getStackTraceAsString(e));
            return Response.fail("supervisionRecord.create.fail");
        }
    }

    /**
     * 更新
     *updateSupervisionRecords
     * @param supervisionRecords
     * @return true or false
     */
    @Override
    public Response<Map<String,Object>> update(SupervisionRecords supervisionRecords,Integer toStatus) {
        try{
            Map<String,Object> map = supervisionRecordsManager.updateSupervisionRecords(supervisionRecords,toStatus);
            return Response.ok(map);
        }catch(Exception e){
            log.error("failed.update {},case:{}",supervisionRecords,Throwables.getStackTraceAsString(e));
            return Response.fail("supervisionRecords update fail");
        }
    }
}
